From f9fec78733d7ebb5d109a39001eb72f63dd36c40 Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 13 Mar 2003 22:33:52 +0000 Subject: [PATCH] Added track handling to GPX. Thanx, Alex! --- gpsbabel/gpx.c | 62 +++- gpsbabel/reference/track/tracks.gpx | 527 ++++++++++++++++++++++++++++ 2 files changed, 581 insertions(+), 8 deletions(-) create mode 100644 gpsbabel/reference/track/tracks.gpx diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 0bad33dad..e79349124 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -24,6 +24,8 @@ static int in_wpt; static int in_rte; +static int in_trk; +static int in_trkpt; static int in_ele; static int in_name; static int in_time; @@ -43,6 +45,8 @@ static int in_gs_log_wpt; static int in_gs_exported; static int in_gs_tbugs; static int in_something_else; +static int in_number; + static xml_tag *cur_tag; static char *cdatastr; static int opt_logpoint = 0; @@ -61,6 +65,7 @@ static void *mkshort_handle; static time_t file_time; static char *gsshortnames = NULL; +static route_head *trk_head; #define MYNAME "GPX" #define MY_CBUF 4096 @@ -295,6 +300,18 @@ gpx_start(void *data, const char *el, const char **attr) in_rte++; tag_wpt(attr); } + else if (strcmp(el, "trk") == 0) { + trk_head = route_head_alloc(); + route_add_head(trk_head); + in_trk++; + } + else if (strcmp(el, "trkpt") == 0) { + in_trkpt++; + tag_wpt(attr); + } + else if (strcmp(el, "number") == 0) { + in_number++; + } else if (strcmp(el, "time") == 0) { in_time++; } @@ -482,6 +499,15 @@ gpx_end(void *data, const char *el) if (in_name && in_wpt && !in_gs_tbugs) { wpt_tmp->shortname = xstrdup(cdatastr); } + if (in_name && in_trk && !in_trkpt) { + trk_head->rte_name = xstrdup(cdatastr); + } + if (in_desc && in_trk && !in_trkpt) { + trk_head->rte_desc = xstrdup(cdatastr); + } + if (in_number && in_trk) { + trk_head->rte_num = atoi(cdatastr); + } if (gsshortnames) { if (in_gs_name && in_wpt && !in_gs_tbugs) { wpt_tmp->notes = xstrdup(cdatastr); @@ -509,7 +535,7 @@ gpx_end(void *data, const char *el) &wpt_tmp->position.altitude.altitude_meters); } if (in_time) { - if ( in_wpt || in_rte) { + if ( in_wpt || in_rte || in_trkpt) { wpt_tmp->creation_time = xml_parse_time( cdatastr ); } @@ -548,6 +574,13 @@ gpx_end(void *data, const char *el) else if (strcmp(el, "rtept") == 0) { /* route_add(wpt_tmp); */ in_rte--; + } else if (strcmp(el, "trk") == 0) { + in_trk--; + } else if (strcmp(el, "trkpt") == 0) { + route_add_wpt(trk_head, wpt_tmp); + in_trkpt--; + } else if (strcmp(el, "number") == 0) { + in_number--; } else if (strcmp(el, "name") == 0) { in_name--; } else if (strcmp(el, "desc") == 0) { @@ -628,6 +661,9 @@ gpx_cdata(void *dta, const XML_Char *s, int len) (in_wpt && in_gs_diff) || (in_wpt && in_gs_terr) || (in_wpt && in_icon) || + (in_trk && in_name) || + (in_trk && in_desc) || + (in_trk && in_number) || (in_time)) { estr = cdatastr + strlen(cdatastr); memcpy(estr, s, len); @@ -881,11 +917,21 @@ gpx_waypt_pr(const waypoint *waypointp) static void gpx_track_hdr(const route_head *rte) { + char * tmp_ent; + fprintf(ofd, "\n"); if (rte->rte_name) { - fprintf(ofd, " \n"); - fprintf(ofd, " \n",rte->rte_name); - fprintf(ofd, " \n"); + tmp_ent = gpx_entitize(rte->rte_name); + fprintf(ofd, "%s\n", tmp_ent); + xfree(tmp_ent); + } + if (rte->rte_desc) { + tmp_ent = gpx_entitize(rte->rte_desc); + fprintf(ofd, "%s\n", tmp_ent); + xfree(tmp_ent); + } + if (rte->rte_num) { + fprintf(ofd, "%d\n", rte->rte_num); } fprintf(ofd, "\n"); } @@ -896,13 +942,13 @@ gpx_track_disp(const waypoint *waypointp) fprintf(ofd, "\n", waypointp->position.latitude.degrees, waypointp->position.longitude.degrees); - if (waypointp->creation_time) { - gpx_write_time(waypointp->creation_time,"time"); - } if (waypointp->position.altitude.altitude_meters != unknown_alt) { - fprintf(ofd, "\n%f\n\n", + fprintf(ofd, "%f\n", waypointp->position.altitude.altitude_meters); } + if (waypointp->creation_time) { + gpx_write_time(waypointp->creation_time,"time"); + } fprintf(ofd, "\n"); } diff --git a/gpsbabel/reference/track/tracks.gpx b/gpsbabel/reference/track/tracks.gpx new file mode 100644 index 000000000..c85708585 --- /dev/null +++ b/gpsbabel/reference/track/tracks.gpx @@ -0,0 +1,527 @@ + + + + +Nature Trail +Acadiana Park Nature Trail +1 + + +20.000000 + + + +13.000000 + + + +5.000000 + + + +6.000000 + + + +0.000000 + + + +5.000000 + + + +0.000000 + + + +3.000000 + + + +0.000000 + + + +0.000000 + + + +1.000000 + + + +2.000000 + + + +2.000000 + + + +2.000000 + + + +1.000000 + + + +0.000000 + + + +0.000000 + + + +1.000000 + + + +9.000000 + + + +3.000000 + + + +6.000000 + + + +0.000000 + + + +4.000000 + + + +0.000000 + + + +6.000000 + + + +7.000000 + + + +4.000000 + + + +7.000000 + + + +0.000000 + + + +0.000000 + + + +1.000000 + + + +18.000000 + + + +38.000000 + + + +1.000000 + + + +3.000000 + + + +18.000000 + + + +12.000000 + + + +1.000000 + + + +3.000000 + + + +19.000000 + + + +19.000000 + + + +20.000000 + + + + + +Hackberry Fishing +Lake Calcasieu +2 + + +2.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +2.000000 + + + +2.000000 + + + +1.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +2.000000 + + + +3.000000 + + + +1.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +3.000000 + + + +3.000000 + + + +3.000000 + + + +7.000000 + + + +8.000000 + + + +5.000000 + + + +1.000000 + + + +2.000000 + + + +5.000000 + + + +3.000000 + + + +0.000000 + + + +2.000000 + + + +8.000000 + + + +1.000000 + + + +0.000000 + + + +0.000000 + + + +1.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +1.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + +0.000000 + + + + + -- 2.30.2